#include "notesdialog.h"

NotesDialog::NotesDialog(QWidget *parent, NotesDialog::Mode mode) : QDialog(parent) {
	ui.setupUi(this);
	if (mode==Show) {
		ui.verticalLayout->removeWidget(ui.plainTextEdit);
		delete ui.plainTextEdit;
		ui.buttonBox->setStandardButtons(QDialogButtonBox::Ok);
		ui.buttonBox->setCenterButtons(true);
	}
	connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
	connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(close()));
}

NotesDialog::~NotesDialog() {
}

QString NotesDialog::getNoteText(QWidget *parent, const QString &title, const QString &caption, const QString &text, bool *ok) {
	NotesDialog *dlg=new NotesDialog(parent, Get);
	dlg->setWindowTitle(title);
	if (!caption.isEmpty())
		dlg->setCaption(caption);
	if (!text.isEmpty())
		dlg->setText(text);

	bool ok_=FALSE;
	QString result;

	ok_=dlg->exec()==QDialog::Accepted;

	if (ok)
		*ok=ok_;

	if (ok_)
		result=dlg->getText();

	delete dlg;
	return result;
}

void NotesDialog::showNote(QWidget *parent, const QString &title, const QString text) {
	NotesDialog *dlg=new NotesDialog(parent, Show);
	dlg->setWindowTitle(title);
	dlg->setCaption(text);
	dlg->exec();
	delete dlg;
	return;
}
